#include <bits/stdc++.h>

using namespace std;

//#define int long long

void solve()
{
    int t, a, b, x, y;
    cin >> t >> a >> b >> x >> y;
    //     10   3    4    2    1
    //     10   4    3    1    2
    auto solve = [&](int t, int a, int b, int x, int y)
    {
        int cur = 0;
        cur += max((t - a + x) / x, 0);
        t -= max((t - a + x)/ x, 0) * x;
        cur += max((t - b + y) / y, 0);
        return cur;
    };
    cout << max(solve(t , a , b , x , y), solve(t , b , a , y , x)) << endl;
}
signed main()
{
    int t; cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}